package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;


@Slf4j
@Api(tags = "护理计划相关接口")
@RestController
@RequestMapping("/nursing/plan")
public class NursingPlanController extends BaseController {
    @Autowired
    private NursingPlanService nursingPlanService;

    @ApiOperation("查询所有护理计划")
    @GetMapping
    public ResponseResult getAllNursingPlan() {
        List<NursingPlanVo> nurList = nursingPlanService.getAllNursingPlan();
        return success(nurList);
    }

    @ApiOperation("新增护理计划")
    @PostMapping
    public ResponseResult insert(
            @ApiParam(value = "护理计划数据传输对象", required = true)
            @RequestBody NursingPlanDto dto) {
        nursingPlanService.insert(dto);
        return success();
    }

    @ApiOperation("条件分页查询")
    @GetMapping("/search")
    public ResponseResult<PageResponse<NursingPlanVo>> pageQuery(
            @ApiParam(name = "name", value = "护理计划名称") String name,
            @ApiParam(name = "status", value = "状态 0禁用 1启用") Integer status,
            @ApiParam(name = "pageNum", value = "当前页")
            @RequestParam(required = false, defaultValue = "1") Integer pageNum,
            @ApiParam(name = "pageSize", value = "每页条数")
            @RequestParam(required = false, defaultValue = "10") Integer pageSize
    ) {
        PageResponse<NursingPlanVo> pageList = nursingPlanService.pageQuery(name, status, pageNum, pageSize);
        return success(pageList);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理计划")
    public ResponseResult getNursingPlanById(
            @ApiParam(name = "id", value = "护理计划id", required = true)
            @PathVariable Long id) {
        NursingPlanVo vo = nursingPlanService.getNursingPlanById(id);
        return ResponseResult.success(vo);
    }

    @PutMapping("/{id}")
    @ApiOperation("修改护理计划")
    public ResponseResult updateNursingPlan(
            @ApiParam(value = "修改护理计划数据传输对象", required = true)
            @RequestBody NursingPlanDto dto) {
        nursingPlanService.updateNursingPlan(dto);
        return ResponseResult.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除护理计划")
    public ResponseResult deleteNursingPlan(
            @ApiParam(name = "id", value = "护理计划id", required = true)
            @PathVariable Long id) {
        nursingPlanService.deleteNursingPlan(id);
        return ResponseResult.success();
    }

    @ApiOperation("启用禁用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateStatus(
            @ApiParam(name = "id", value = "护理计划id", required = true)
            @PathVariable Long id,
            @ApiParam(name = "status", value = "护理计划状态", required = true)
            @PathVariable Integer status) {
        nursingPlanService.updateStatus(id, status);
        return ResponseResult.success();
    }
}
